package cn.stylefeng.guns.modular.api;

import cn.stylefeng.guns.modular.quan.service.CouponReceiveService;
import cn.stylefeng.guns.modular.quan.service.CouponService;
import cn.stylefeng.roses.core.base.controller.BaseController;
import cn.stylefeng.roses.kernel.model.response.ResponseData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/webapi")
public class QuanApiController extends BaseController {

    @Autowired
    private CouponService couponService;
    @Autowired
    private CouponReceiveService couponReceiveService;

    /**
     * 获取优惠券列表
     * @return
     */
    @RequestMapping(value = "/getCouponList")
    @ResponseBody
    public ResponseData getCouponList(String userId){
        return ResponseData.success(couponService.getCouponList(userId));
    }

    /**
     * 获取优惠券详情
     * @return
     */
    @RequestMapping(value = "/getCouponDetail")
    @ResponseBody
    public ResponseData getCouponDetail(String userId,Long couponId){
        return ResponseData.success(couponService.getCouponDetail(userId,couponId));
    }

    /**
     * 领取优惠券
     * @param userId
     * @return
     */
    @RequestMapping(value = "/receiveCoupon")
    @ResponseBody
    public ResponseData receiveCoupon(String userId, Long couponId){
        return ResponseData.success(couponReceiveService.receiveCoupon(userId,couponId));
    }

    /**
     * 获取我的优惠券
     * @param userId
     * @return
     */
    @RequestMapping(value = "/getCouponById")
    @ResponseBody
    public ResponseData getCouponById(String userId){
        return ResponseData.success(couponReceiveService.getCouponById(userId));
    }

    /**
     * 获取已经领取的优惠券详情
     * @return
     */
    @RequestMapping(value = "/getCouponDetailByUser")
    @ResponseBody
    public ResponseData getCouponDetailByUser(String userId,Long couponId){
        return ResponseData.success(couponReceiveService.getCouponDetailByUser(userId,couponId));
    }


}
